package com.kkb.kkbportal.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.kkbcommon.exception.Asserts;
import com.kkb.kkbportal.dao.RecommendMapper;
import com.kkb.kkbportal.domain.Recommend;
import com.kkb.kkbportal.service.RecommendService;
import com.kkb.kkbportal.service.util.RecommendValidateUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author qtds
 * @since 2021-08-11
 */
@Service
public class RecommendServiceImpl extends ServiceImpl<RecommendMapper, Recommend> implements RecommendService {

    @Override
    public PageInfo<Recommend> findPage(Recommend condition, Integer pageNum, Integer pageSize) {
        return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> {
            this.selectByCondition(condition);
        });
    }

    @Override
    public List<Recommend> selectByCondition(Recommend recommend) {
        if (ObjectUtil.isNull(recommend)) {
            return list();
        }

        Integer companyIsListed = recommend.getCompanyIsListed();
        Integer companySize = recommend.getCompanySize();
        String positionCity = recommend.getPositionCity();
        String positionEducation = recommend.getPositionEducation();
        // 条件查询案例（参考代码和群内文档）
        List<Recommend> list = this.lambdaQuery()
                // eq方法，参数：
                // boolean：是否加入到where条件中, 函数：实体类的get方法, val:where条件的值（如：where id=1）
                .eq(ObjectUtil.isNotEmpty(positionCity), Recommend::getPositionCity, positionCity)
                .eq(ObjectUtil.isNotNull(companyIsListed), Recommend::getCompanyIsListed, companyIsListed)
                .eq(ObjectUtil.isNotNull(companySize), Recommend::getCompanySize, companySize)
                .eq(ObjectUtil.isNotEmpty(positionEducation), Recommend::getPositionEducation, positionEducation)
                // 最后加个list即可
                .list();

        if (CollUtil.isEmpty(list)) {
            Asserts.fail("未找到数据");
        }
        return list;
    }

}
